package evaluation;

import java.util.Iterator;
import java.util.List;

public class EvaluationTool {
	
	public static int [] rawStatistics(List<Integer> labelList, List<Integer> predictList) {
		Iterator<Integer> lItr = labelList.iterator();
		Iterator<Integer> pItr = predictList.iterator();

		int tp = 0;
		int tn = 0;
		int fp = 0;
		int fn = 0;
		while(pItr.hasNext()) {
			int l = lItr.next();
			int p = pItr.next();
			
			if(l == 1) {
				if(p == 1) {
					tp ++;
				} else {
					fn ++;
				}
			} else {
				if(p == 1) {
					fp ++;
				} else {
					tn ++;
				}
			}
		}
		
		int [] result = new int[4];
		result[0] = tp;
		result[1] = tn;
		result[2] = fp;
		result[3] = fn;
		return result;
	}
	
	public static double getNDCR(int tp, int tn, int fp, int fn, double hours) {
		// formal evaluation
		double N_Miss = fn;
		double N_Targ = tp + fn;
		double N_FA = fp;
		double T_Source = hours;
		
		double P_Miss = N_Miss / N_Targ;
		double R_FA = N_FA / T_Source;
		
		double NDCR = P_Miss + 0.005 * R_FA;
		return NDCR;
	}
	
	public static double getNDCR(List<Integer> labelList, List<Integer> predictList, double hours) {
		int [] raw = rawStatistics(labelList, predictList);
		return getNDCR(raw[0], raw[1], raw[2], raw[3], hours);
	}
}
